<?php
class Fe_docs_model extends CI_Model {
	
	function __construct()
	{
			parent::__construct();
	}	
	
    
	function _get_docs_cate_list() {
			$db = $this->load->database('default', TRUE);
			$sql = "SELECT * FROM docs_cate order by cate_id desc";
			$query = $db->query($sql);
			return $query->result();
	}	
	
	function get_docs_cate_nopaging($parentid, $start, $count) {
			$db = $this->load->database('default', TRUE);
			$sql = "SELECT cate_id,cate_name,url 
							FROM docs_cate 
							WHERE parent_id=? and docs_cate.status='1' order by docs_cate.cate_id desc LIMIT ?,?;";

			$query = $db->query($sql, array($parentid, $start, $count));
			return array($query->result());
	}	
	
    function get_docs_paging($docs_cate_id, $start, $count) {
        $db = $this->load->database('default', TRUE);
        $sql = "SELECT count(docs.docs_id) c 
            FROM docs INNER JOIN docs_cate on docs_cate.cate_id = docs.cate_id		
            WHERE docs.cate_id in (?) and docs.status='1';";
        $query = $db->query($sql, array($docs_cate_id));
        $aRows = $query->result();
        $iRow_Count = $aRows[0]->c;
        $sql = "SELECT docs.docs_id,docs.title,docs.desc,docs.file,docs.create_date,docs.issue_date,docs.apply_date,docs.views_count,docs.source,docs_cate.cate_name,docs_cate.url as docs_cate_url
                FROM docs INNER JOIN docs_cate on docs_cate.cate_id = docs.cate_id		
                WHERE docs.cate_id in (?) and docs.status='1' 
                order by issue_date desc
                LIMIT ?,?;";
        $query = $db->query($sql, array($docs_cate_id, $start, $count));
        $result = $query->result();
        return array($iRow_Count, $result);
    }	
		

    //docs search
    function _search_docs_list($cate_id, $keywords, $limit_from, $limit_to) {
        $db = $this->load->database('default', TRUE);
        $sql = "SELECT count(docs.docs_id) c 
            FROM docs INNER JOIN docs_cate on docs_cate.cate_id = docs.cate_id		
            WHERE 1=1 and docs.status='1' ";
        if ($keywords != "")
            $sql.=" and docs.title like N'%" . $keywords . "%' ";
        if ($cate_id != "")
            $sql.=" and docs.cate_id=" . $cate_id;
        $sql.=" order by docs_id DESC;";
        $query = $db->query($sql);
        $aRows = $query->result();
        $iRow_Count = $aRows[0]->c;

        $sql = "SELECT docs.docs_id,docs.title,docs.desc,docs.file,docs.create_date,docs.issue_date,docs.apply_date,docs.views_count,docs.source,docs_cate.cate_name,docs_cate.url as docs_cate_url
                FROM docs INNER JOIN docs_cate on docs_cate.cate_id = docs.cate_id		
                WHERE 1=1 and docs.status='1' ";
        if ($keywords != "")
            $sql.=" and docs.title like N'%" . $keywords . "%' ";
        if ($cate_id != "")
            $sql.=" and docs.cate_id=" . $cate_id;
        $sql.=" order by docs_id DESC LIMIT {$limit_from},{$limit_to};";
        $query = $db->query($sql);
        $result = $query->result();
        return array($iRow_Count, $result);
    }		
}
?>